import request from '@/utils/request'

//获取用户信息
export const saveUser = (payload) => {
  return {
    type: 'profile/saveUser',
    payload,
  }
}
export const getUser = () => {
  return async (dispatch) => {
    const res = await request.get('/user')
    // console.log(res.data.data)
    dispatch(saveUser(res.data.data))
  }
}
//获取个人信息
export const saveUserProfile = (payload) => {
  return {
    type: 'profile/saveUserProfile',
    payload,
  }
}
export const getUserProfile = () => {
  return async (dispatch) => {
    const res = await request.get('/user/profile')
    // console.log(res.data.data)
    dispatch(saveUserProfile(res.data.data))
  }
}
//修改昵称
export const editUserName = (data) => {
  return async (dispatch) => {
    const res = await request.patch('/user/profile', data)
    console.log(res)
    dispatch(getUserProfile())
  }
}
